var date = {
	/*
	 *各位数字转成两位显示：如3 -> 03，对非各位数不做处理,即：12 -> 12
	 * */
	parseToDouble(val){
					if(String(val).length < 2){
						return '0' + val;
					}
					return val;
			},
	/*
			 * 格式化时间
			 * @time：时间戳
			 * @format：y-m-d h:i:s , y/m/d h-i-s , y-m-d , h-i-s , h , h-s , m-d,y年m月d日
			 * 注：连接符号可以为任意非字母字符
			 * */
	format:function(time,format){
		if(Object.prototype.toString.call(time) != "[object Date]"){
					console.warn("传入时间不是Date对象")
				}
				var date = new Date(time);
				let y = date.getFullYear();
				let m = this.parseToDouble(date.getMonth() + 1);
				let d = this.parseToDouble(date.getDate());
				if(!format){
					return y + "-" + m + "-" + d
				}
				
				let h = this.parseToDouble(date.getHours());
				let i = this.parseToDouble(date.getMinutes());
				let s = this.parseToDouble(date.getSeconds());
				let ConnectSymbol = format.match(/\W/g);
				let items = format.match(/\w/g);
				let res = '';
				for(var j = 0; j < items.length; j++){
					if(j != 0 && j != items.length){
						res +=  ConnectSymbol[j-1]
					}
					switch(items[j].toLocaleLowerCase()){
						case 'y':
							res += y;
							break;
						case 'm':
							res += m;
							break;
						case 'd':
							res += d;
							break;
						case 'h':
							res += h;
							break;
						case 'i':
							res += i;
							break;
						case 's':
							res += s;
							break;
						default:
							console.error("标志符仅限于y,m,d,h,i,s，不区分大小写")
					}
				}
				return res;
	}
}
export default date